package com.zyd.shiro.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zyd.shiro.business.entity.User;
import com.zyd.shiro.business.service.SchoolService;
import com.zyd.shiro.business.vo.SchoolConditionVO;
import com.zyd.shiro.framework.exception.ZhydException;
import com.zyd.shiro.persistence.beans.School;
import com.zyd.shiro.persistence.beans.SysUser;
import com.zyd.shiro.persistence.mapper.SchoolMapper;
import com.zyd.shiro.util.PasswordUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class SchoolServiceImpl implements SchoolService {

    @Autowired
    private SchoolMapper schoolMapper;

    @Override
    public PageInfo<School> findPageBreakByCondition(SchoolConditionVO vo) {
        PageHelper.startPage(vo.getPageNumber(), vo.getPageSize());
        List<School> schools = schoolMapper.findPageBreakByCondition(vo);
        if (CollectionUtils.isEmpty(schools)) {
            return null;
        }
        PageInfo bean = new PageInfo<School>(schools);
        bean.setList(schools);
        return bean;
    }

    @Override
    public List<School> selectAllSchool() {
        return schoolMapper.selectAllSchool();
    }

    @Override
    public School insert(School entity) {
        Assert.notNull(entity, "School不可为空！");
        entity.setCreateTime(new Date());
        entity.setUpdateTime(new Date());
        schoolMapper.insertSchool(entity);
        return entity;
    }

    @Override
    public void insertList(List<School> entities) {

    }

    @Override
    public boolean removeByPrimaryKey(Long primaryKey) {
        return schoolMapper.deleteByPrimaryKey(primaryKey) > 0;
    }

    @Override
    public boolean update(School entity) {
        return false;
    }

    @Override
    public boolean updateSelective(School entity) {
        Assert.notNull(entity, "School不可为空！");
        entity.setUpdateTime(new Date());
        return schoolMapper.updateById(entity) > 0;
    }

    @Override
    public School getByPrimaryKey(Long primaryKey) {
        Assert.notNull(primaryKey, "PrimaryKey不可为空！");
        School school = schoolMapper.selectById(primaryKey);
        return null == school ? null : school;
    }

    @Override
    public School getOneByEntity(School entity) {
        return null;
    }

    @Override
    public List<School> listAll() {
        return null;
    }

    @Override
    public List<School> listByEntity(School entity) {
        return null;
    }
}
